//
//  LGMedicineManageHeader.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/10/9.
//

#import "LGMedicineManageHeader.h"

@interface LGMedicineManageHeader()

/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *subTitleLabel;

@end

@implementation LGMedicineManageHeader
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setType:(NSString *)type{
    _type = type;
    if([type isEqualToString:@"advice"]){
        //用药方案
        self.iconView.image = [UIImage imageNamed:@"用药管理-用药方案"];
        self.titleLabel.text = @"用药方案";
        self.subTitleLabel.hidden = YES;
        [self.checkBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-viewPix(16));
            make.centerY.equalTo(self.iconView);
            make.width.equalTo(@(viewPix(70)));
            make.height.equalTo(@(viewPix(30)));
        }];
    }else{
        //用药记录
        self.iconView.image = [UIImage imageNamed:@"用药管理-用药记录"];
        self.titleLabel.text = @"用药记录";
        self.subTitleLabel.hidden = NO;
        [self.checkBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-viewPix(16));
            make.centerY.equalTo(self.subTitleLabel);
            make.width.equalTo(@(viewPix(70)));
            make.height.equalTo(@(viewPix(30)));
        }];
    }
}



#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self addSubview:self.iconView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.subTitleLabel];
    [self addSubview:self.checkBtn];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.iconView);
    }];
    [self.checkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-viewPix(16));
        make.centerY.equalTo(self.iconView);
        make.width.equalTo(@(viewPix(70)));
        make.height.equalTo(@(viewPix(30)));
    }];
}
-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(10), viewPix(24), viewPix(24))];
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UILabel *)subTitleLabel{
    if(!_subTitleLabel){
        _subTitleLabel = [UILabel lableWithText:@"医助采集" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _subTitleLabel.frame = CGRectMake(viewPix(16), kMaxY(self.iconView.frame)+viewPix(12), viewPix(150), viewPix(21));
    }
    return _subTitleLabel;
}

-(UIButton *)checkBtn{
    if(!_checkBtn){
        _checkBtn = [UIButton buttonWithTitle:@"查看全部" titleFont:LGFont(13) textColor:@"#999999" imageName:@"grayTip12"];
        _checkBtn.bounds = CGRectMake(0, 0, viewPix(70), viewPix(30));
        _checkBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [_checkBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:5];
    }
    return _checkBtn;
}


@end
